/**
 * 
 */
package com.effectivsocial.core.spring;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.inject.Named;


import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;



/**
 * @author Dhrubo
 *
 */
@Named
public class ApplicationContextHelper implements ApplicationContextAware, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private ApplicationContext context;
	
	
	
	/* (non-Javadoc)
	 * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
	 */
	@Override
	public void setApplicationContext(ApplicationContext context)
			throws BeansException {
		this.context = context;

	}
	
	
	
	public ApplicationContext getContext() {
		return context;
	}



	public void setContext(ApplicationContext context) {
		this.context = context;
	}

	public List getBeansByType(Class clazz) {
		List list = new ArrayList( getBeansOfType(clazz).values());
		return list;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public Map getBeansOfType(Class clazz) {
		
		return this.context.getBeansOfType(clazz);
	}
	
	public Object getBean(String beanName) {
		return context.getBean(beanName);
	}
	
	
	
}
